<template>
  <!-- 对话框客户跟进记录 -->
  <el-dialog
    title="意向业务备注"
    :visible="addFollowDialog"
    :close-on-click-modal="false"
    center
    @close="closeAddFollowDialog"
    width="50%"
  >
    <el-input
      type="textarea"
      placeholder="请输入跟进内容"
      :rows="5"
      v-model="textareaValue"
      maxlength="200"
      show-word-limit
    >
    </el-input>
    <span slot="footer" class="dialog-footer">
      <el-button @click="closeAddFollowDialog">取 消</el-button>
      <el-button type="primary" @click="addIntentionCustomer">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { addIntentionCustomerApi } from '@/api/anxu'
export default {
  name: 'addanxu-dialog',
  props: {
    addFollowDialog: {
      type: Boolean,
      default: false
    },
    company_id: {
      type: Number,
      default: 0
    },
    // 获取 我的安许 列表
    getMyAnxuList: {
      type: Function,
      default: null
    }
  },
  created () {},
  data () {
    return {
      textareaValue: ''
    }
  },
  methods: {
    // 关闭弹窗
    closeAddFollowDialog () {
      this.$emit('closeAddFollowDialog')
      // 清空文本域
      this.textareaValue = ''
    },
    // 添加 意向客户
    async addIntentionCustomer () {
      if (this.textareaValue === '') {
        return this.$message({
          showClose: true,
          message: '请填写跟进公司意向业务!',
          type: 'warning',
          duration: 1500
        })
      }
      const { data: res } = await addIntentionCustomerApi(
        this.company_id,
        this.textareaValue
      )
      // console.log('添加意向客户', res)
      if (res.code === 200) {
        this.$emit('closeAddFollowDialog')
        this.textareaValue = ''
        this.$message({
          showClose: true,
          message: '已成功添加到我的意向客户!',
          type: 'success',
          duration: 1500
        })
        // 渲染 我的安许 列表
        this.getMyAnxuList()
      }
    }
  },
  watch: {}
}
</script>

<style lang="scss">
.el-dialog {
  .el-dialog__header {
    background-color: rgb(84, 92, 100);
    padding: 20px 20px 20px;
    .el-dialog__title {
      color: #fff;
    }
  }
}
</style>
